import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import {
  AuditedArticleList,
  ArticlePending,
  ArticleDisabled,
  ArticleFailure,
  Layout,
  Login,
  Home,
  ClientUser,
  AdminUser,
  UserInfo,
  FileInfo,
  ServiceMessage,
  SystemMessage,
  HealthChart,
  ChartInfo,
  HealthData,
  ZGrade,
  TestRule,
  TestPrice,
  RuleInfo,
  Template,
  SearchAI,
  TemplateInfo,
  Paper,
  PaperSearch,
  PaperInfo,
  Image,
  HealthDiet,
  Room,
  Consume,
  Income,
  Bmi,
  SaleList,
  SaleTotal,
  SaleDetail,
  Vaccine,
  Temperature,
  UserActive,
  ResultTemplate,
  MemberConsume,
  TemperatureStatistics,
  MentalHealth,
  MentalDetail,
  MentalQuestion,
  JustForTest,
  Article,
  MentalStatistics,
  WriteArticle,
  UserAuthority,
  SetAuthority,
  ChartCategory,
  Hospital,
  Doctor,
  DoctorInformation,
  Area,
  MentalUser,
  MentalUserDetail,
  School,
  TestResultTemplate,
  NotFound,
  HospitalDetail,
  Banner,
  WithDraw,
  ChartRecommend,
  FitbarPageData,
  KeyWord,
  AddOrganization,
  KnowledgeList,
  OrganizationList,
  CompanyInfo,
  ArticleList,
  VideoList,
  ArticleDetail,
  VideoDetail,
  DataAnalysis,
  BusinessCard,
  CompanyChart,
  TestReport,
  CompanyKnowledge,
  ActiveItem,
  TemperatureAndMoveLine,
  FiremanCareer,
  MemberList,
  SportRule,
  SubjectGrade,
  Device,
  adList,
  MenberList,

} from '../views'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: {
      isPublic: true
    }
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: '/home',
    children: [
      {path: 'home', component: Home, name: 'Home', meta: {path: ['首页']}},
      {path: 'user/client', component: ClientUser, name: 'ClientUser', meta: {path: ['用户管理', '注册用户'], keepAlive: true}},
      {path: 'user/admin', component: AdminUser, name: 'AdminUser', meta: {path: ['用户管理', '管理用户']}},
      {
        path: 'user/authority',
        component: UserAuthority,
        name: 'UserAuthority',
        meta: {path: ['用户管理', '权限管理'], keepAlive: true}
      },
      {
        path: 'user/authority/set/:roleId',
        component: SetAuthority,
        name: 'SetAuthority',
        meta: {path: ['用户管理', '权限管理', '权限设置']},
        props: true
      },
      {path: 'user/info', component: UserInfo, name: 'UserInfo', meta: {path: ['用户管理', '注册用户', '用户详情']}, props: true},
      {
        path: 'user/relative/:id/:name',
        component: FileInfo,
        name: 'FileInfo',
        meta: {path: ['用户管理', '注册用户', '家庭成员详情']},
        props: true
      },
      {path: 'message/service', component: ServiceMessage, name: 'ServiceMessage', meta: {path: ['消息管理', '服务类消息']}},
      {path: 'message/system', component: SystemMessage, name: 'SystemMessage', meta: {path: ['消息管理', '系统消息']}},
      {path: 'chart/category', component: ChartCategory, name: 'ChartCategory', meta: {path: ['健康档案管理', '表类目管理']}},
      {path: 'file/all', component: HealthChart, name: 'HealthChart', meta: {path: ['健康档案管理', '健康档案总表维护']}},
      {
        path: 'file/chart/:type/:name/:id',
        component: ChartInfo,
        name: 'ChartInfo',
        meta: {path: ['健康档案管理', '健康档案总维护', '评测表详情']},
        props: true
      },
      {path: 'file/data', component: HealthData, name: 'HealthData', meta: {path: ['健康档案管理', '数据维护']}},
      {path: 'file/grade', component: ZGrade, name: 'ZGrade', meta: {path: ['健康档案管理', 'Z评分设置维护']}},
      {path: 'file/bmi', component: Bmi, name: 'bmi', meta: {path: ['健康档案管理', 'BMI设置维护']}},
      {path: 'test/rule', component: TestRule, name: 'TestRule', meta: {path: ['健康测评', '健康测评规则设置']}},
      {path: 'test/price', component: TestPrice, name: 'TestPrice', meta: {path: ['健康测评', '健康测评价格设置']}},
      {
        path: 'test/mental',
        component: MentalHealth,
        name: 'MentalHealth',
        meta: {path: ['健康测评', '心理健康测试表管理'], keepAlive: true}
      },
      {
        path: 'test/mental_question',
        component: MentalQuestion,
        name: 'MentalQuestion',
        meta: {path: ['健康测评', '心理健康题库管理']}
      },
      {
        path: 'test/mental/:id',
        component: MentalDetail,
        name: 'MentalDetail',
        meta: {path: ['健康测评', '心理健康测试表管理', '心理健康测试详情']},
        props: true
      },
      {
        path: 'test/rule/:type/:id/:max/:min',
        component: RuleInfo,
        name: 'RuleInfo',
        meta: {path: ['健康测评', '健康测评规则设置', '测评详细设置']},
        props: true
      },
      {path: 'template/setting', component: Template, name: 'Template', meta: {path: ['模板设置', 'AI模板设置']}},
      {path: 'template/search', component: SearchAI, name: 'SearchAI', meta: {path: ['模板设置', '查询AI模板']}},
      {
        path: 'template/:id',
        component: TemplateInfo,
        name: 'TemplateInfo',
        meta: {path: ['模板设置', 'AI模板详情']},
        props: true
      },
      {path: 'template/paper/setting', component: Paper, name: 'Paper', meta: {path: ['模板设置', '调查问卷模板设置']}},
      {
        path: 'template/test/result',
        component: TestResultTemplate,
        name: 'TestResultTemplate',
        meta: {path: ['模板设置', '健康测评结果模板设置']}
      },
      {path: 'template/paper/search', component: PaperSearch, name: 'PaperSearch', meta: {path: ['模板设置', '调查问卷模板查询']}},
      {
        path: 'template/paper/:id/:name',
        component: PaperInfo,
        name: 'PaperInfo',
        meta: {path: ['模板设置', '调查问卷模板详情']},
        props: true
      },
      {path: 'image', component: Image, name: 'Image', meta: {path: ['图片管理']}},
      {path: 'product/diet', component: HealthDiet, name: 'HealthDiet', meta: {path: ['产品设置', '健康食谱设置']}},
      {path: 'product/storage', component: Room, name: 'Room', meta: {path: ['产品设置', '存储空间设置']}},
      {path: 'product/device', component: Device, name: 'Device', meta: {path: ['产品设置', '设备管理']}},
      {path: 'statistics/consume', component: Consume, name: 'Consume', meta: {path: ['统计分析', '用户消费统计']}},
      {
        path: 'statistics/mental/:name',
        component: MentalStatistics,
        name: 'MentalStatistics',
        meta: {path: ['统计分析', '心理统计'], keepAlive: false}
      },
      // { path: 'statistics/mental/report/:mId/:orderNum/:cname/:qtime/', component: TestReport, name: 'TestReport', meta: { path: ['统计分析', '心理统计', '结果报表'] }, props: true },
      {
        path: 'statistics/mental/report/:mId/:orderNum/:cname/:qtime/',
        component: TestReport,
        name: 'TestReport',
        meta: {path: ['统计分析', '心理统计', '结果报表']},
        props: true
      },
      {path: 'finance/income', component: Income, name: 'Income', meta: {path: ['财务管理', '收支查询']}},
      {path: 'sale/list', component: SaleList, name: 'SaleManList', meta: {path: ['销售统计', '销售员列表']}},
      {path: 'sale/statistics', component: SaleTotal, name: 'SaleManTotal', meta: {path: ['销售统计', '销售员统计']}},
      {path: 'member/statistics', component: MemberConsume, name: 'MemberConsume', meta: {path: ['统计分析', '成员统计']}},
      {path: 'sale/detail/:id', component: SaleDetail, name: 'SaleDetail', meta: {path: ['销售统计', '推广详情']}, props: true},
      {path: 'vaccine', component: Vaccine, name: 'Vaccine', meta: {path: ['疫苗管理', '疫苗列表']}},
      {path: 'temperature', component: Temperature, name: 'Temperature', meta: {path: ['统计分析', '体温打卡']}},
      //--------------------------我改了
      {
        path: 'statistics/temperature/:name',
        component: TemperatureStatistics,
        name: 'TemperatureStatistics',
        meta: {path: ['统计分析', '体温打卡统计'], keepAlive: false}
      },
      {path: 'buried-point', component: UserActive, name: 'UserActive', meta: {path: ['用户行为记录']}},
      {path: 'result/template', component: ResultTemplate, name: 'ResultTemplate', meta: {path: ['添加测评结果模板']}},
      {path: 'for_test', component: JustForTest, name: 'JustForTest', meta: {path: ['测试']}},
      {path: 'school', component: School, name: 'School', meta: {path: ['学校管理', '学校管理']}},

      {path: 'article/new', component: WriteArticle, name: 'WriteArticle', meta: {path: ['文章管理', '新建文章']}},
      {path: 'mental/hospital', component: Hospital, name: 'Hospital', meta: {path: ['心理临床管理', '医院管理']}},
      {
        path: 'mental/hospital/:id/:name',
        component: HospitalDetail,
        name: 'HospitalDetail',
        meta: {path: ['心理临床管理', '医院管理', '医院详情']},
        props: true
      },
      {path: 'mental/doctor', component: Doctor, name: 'Doctor', meta: {path: ['心理临床管理', '医生管理']}},
      {path: 'mental/user', component: MentalUser, name: 'MentalUser', meta: {path: ['心理临床管理', '知心意用户管理']}},
      {
        path: 'mental/user/:id/:nickname',
        component: MentalUserDetail,
        name: 'MentalUserDetail',
        meta: {path: ['心理临床管理', '用户详情']},
        props: true
      },
      {
        path: 'mental/doctor/detail/:id/:status',
        component: DoctorInformation,
        name: 'DoctorInformation',
        meta: {path: ['心理临床管理', '医生管理', '医生信息']},
        props: true
      },
      {path: 'mental/area', component: Area, name: 'Area', meta: {path: ['心理临床管理', '地区管理']}},
      {path: 'banner', component: Banner, name: 'Banner', meta: {path: ['轮播图管理', '轮播图管理']}},
      {
        path: 'chart_manage/recommend',
        component: ChartRecommend,
        name: 'ChartRecommend',
        meta: {path: ['量表管理', '推荐量表设置']}
      },
      {
        path: 'page_setting/fitbar',
        component: FitbarPageData,
        name: 'FitbarPageData',
        meta: {path: ['页面数据设置', '健康尺页面数据设置']}
      },
      {path: 'organization/add', component: AddOrganization, name: 'AddOrganization', meta: {path: ['机构管理', '添加机构']}},
      {
        path: 'organization/list',
        component: OrganizationList,
        name: 'OrganizationList',
        meta: {path: ['机构管理', '机构列表'], keepAlive: true}
      },
      {
        path: 'organization/knowledge/:id/:name',
        component: CompanyKnowledge,
        name: 'CompanyKnowledge',
        meta: {path: ['机构管理', '推文列表']},
        props: true
      },
      {path: 'mental/withDraw', component: WithDraw, name: 'WithDraw', meta: {path: ['心理临床管理', '提现管理']}},
      {path: 'knowledge/list', component: KnowledgeList, name: 'KnowledgeList', meta: {path: ['知识管理', '知识列表']}},
      {path: 'company/information', component: CompanyInfo, name: 'CompanyInfo', meta: {path: ['公司管理', '公司基本信息']}},
      {
        path: 'operation/article/list',
        component: ArticleList,
        name: 'ArticleList',
        meta: {path: ['机构管理','查看成员', '文章'], keepAlive: true}
      },

      // -------------已审核的文章或视频--------
      {
        path: '/operation/auditedArticle/list',
        component: AuditedArticleList,
        name: 'AuditedArticleList',
        meta: {path: ['机构管理','查看成员', '已审核'], keepAlive: true}
      },
      {
        path: '/operation/pendingArticle/list',
        component: ArticlePending,
        name: 'ArticlePending',
        meta: {path: ['机构管理','查看成员', '待审核'], keepAlive: true}
      },
      {
        path: '/operation/failureArticle/list',
        component: ArticleFailure,
        name: 'ArticleFailure',
        meta: {path: ['机构管理','查看成员', '审核失败'], keepAlive: true}
      },
      {
        path: '/operation/disabledArticle/list',
        component: ArticleDisabled,
        name: 'ArticleDisabled',
        meta: {path: ['机构管理','查看成员', '系统禁用'], keepAlive: true}
      },



      // -----------------------------------------------------
      {path: 'operation/ad/adList', component: adList, name: 'adList', meta: {path: ['推文管理', '知识广告']}},
      {path: 'operation/video/list', component: VideoList, name: 'VideoList', meta: {path: ['推文管理', '视频列表']}},
      
      
      {path: 'operation/add', component: Article, name: 'Article', meta: {path: ['推文管理', '添加推文']}},
      {
        path: 'operation/article/detail/:id',
        component: ArticleDetail,
        name: 'ArticleDetail',
        meta: {path: ['推文管理', '文章详情']},
        props: true
      },
      {
        path: 'operation/video/detail/:id',
        component: VideoDetail,
        name: 'VideoDetail',
        meta: {path: ['推文管理', '视频详情']},
        props: true
      },
      {path: 'operation/analysis', component: DataAnalysis, name: 'DataAnalysis', meta: {path: ['推文管理', '数据分析']}},
      {path: 'operation/keyword', component: KeyWord, name: 'KeyWord', meta: {path: ['推文管理', '关键字管理']}},
      {path: 'user/businessCard', component: BusinessCard, name: 'BusinessCard', meta: {path: ['用户管理', '名片管理']}},
      {
        path: 'organization/chart/:name/:id',
        component: CompanyChart,
        name: 'CompanyChart',
        meta: {path: ['机构管理', '设置量表']},
        props: true
      },
      {path: 'sports/item', component: ActiveItem, name: 'ActiveItem', meta: {path: ['体育管理', '体育项管理']}},
      {path: 'sports/rule', component: SportRule, name: 'SportRule', meta: {path: ['体育管理', '科目规则设置']}},
      {
        path: 'member/temperature/:id',
        component: TemperatureAndMoveLine,
        name: 'TemperatureAndMoveLine',
        meta: {path: ['健康数据']},
        props: true
      },
      {path: 'fireman/career', component: FiremanCareer, name: 'FiremanCareer', meta: {path: ['消防管理', '职务管理']}},
      // {path: 'member/list', component: MemberList, name: 'MemberList', meta: {path: ['成员管理', '成员列表']}},
      {
        path: 'member/sportsGrade/:id/:name',
        component: SubjectGrade,
        name: 'SubjectGrade',
        meta: {path: ['成员列表', '体能成绩']},
        props: true
      },
      // 后加的
      {
        path: 'organization/memberlist/:type/:name/:id',
        component: MemberList,
        name: 'MemberList',
        meta:{path:['机构管理','查看成员']},
        props: true
      }

      // { path:  }
    ]
  },
  {
    path: '*',
    name: '404',
    component: NotFound,
    meta: {
      isPublic: true
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  if (!to.meta.isPublic && !sessionStorage.getItem('X-Token')) {
    next('/login')
  } else {
    NProgress.start()
    next()
  }
})
router.afterEach(() => {
  NProgress.done()
})

export default router
